package com.doit.day03.不可变集合

object _11_Map {
  def main(args: Array[String]): Unit = {
    val map: Map[Int, String] = Map( 1 -> "zss", 2 -> "lss")

    val map1: Map[Int, String] = Map((1, "zss"), (2, "lss"))

    //想将key都变成*10 将value 变成大写
    val res: Map[Int, String] = map1.map( tp => {
      val key: Int = tp._1
      val value: String = tp._2
      (key * 10, value.toUpperCase())
    })

//    res.foreach(println)

    //Option 封装有值和null的  some   none
    val maybeString: Option[String] = map1.get(2)
    if(maybeString.isDefined){
      val value: String = maybeString.get
      println(value)
    }else{
      println("没有这个key，取个锤子啊")
    }

    //getOrDefault
    val str: String = map.getOrElse(2, "nihaoya")

    for (elem <- map) {
      val key: Int = elem._1
      val value: String = elem._2
    }







  }

}
